package com.vf.cloud.scene.mvc.ue.service.impl;

import java.util.LinkedList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.vf.cloud.common.util.R;
import com.vf.cloud.scene.common.domain.SubLayerStylePoi;
import com.vf.cloud.scene.common.domain.SubPoi;
import com.vf.cloud.scene.common.vo.ue.poi.LabelForUE;
import com.vf.cloud.scene.common.vo.ue.poi.LabelForUEItem;
import com.vf.cloud.scene.common.vo.ue.poi.MarkerForUE;
import com.vf.cloud.scene.common.vo.ue.poi.MarkerForUEItem;
import com.vf.cloud.scene.common.vo.ue.poi.POIForUE;
import com.vf.cloud.scene.mvc.ue.service.IPOIService;

@Service
public class POIService implements IPOIService{

	@Override
	public R<List<POIForUE>> findList(String identify) {
List<SubPoi> poiList=SubPoi.dao.find("select * from poi where id in ( select e.element_id FROM layer_element e ,layer l WHERE e.layer_id=l.id and l.identify=?)",identify);
		
		SubLayerStylePoi stylePoi=SubLayerStylePoi.dao.findFirst("select * from layer_style_poi  s, layer l   where  s.id=l.id and l.identify=? ",identify);
		if(stylePoi==null) {
			return R.failed();
		}
		
		List<POIForUE> res = new LinkedList<POIForUE>();
		for(SubPoi poi:poiList) {

			POIForUE poiForUE=new POIForUE();
			poiForUE.setId(poi.getId());
			poiForUE.setCoord_type(poi.getCoordType());
			poiForUE.setCoord(poi.getCoord());
			poiForUE.setSpace(stylePoi.getSpace());
//			poiForUE.setShow_icon(stylePoi.getShowIcon());
			poiForUE.setShow_icon(true);
			poiForUE.setShow_range(stylePoi.getShowRange());
			
			LabelForUE labelForUE=new LabelForUE();
			
			/**
			 * POI点Label normal 样式组装
			 */
			LabelForUEItem normalLabel=new LabelForUEItem();
			normalLabel.setText(poi.getCnText());
//			normalLabel.setShow_label(stylePoi.getLabelNormalShowLabel());
			normalLabel.setShow_label(true);
			normalLabel.setFont_size(stylePoi.getLabelNormalFontSize());
			normalLabel.setFont_style(stylePoi.getLabelNormalFontStyle());
			normalLabel.setFont_family(stylePoi.getLabelNormalFontFamily());
			normalLabel.setColor(stylePoi.getLabelNormalFontColor());
			normalLabel.setOutline_size(stylePoi.getLabelNormalFontOutlineSize());
			normalLabel.setOutline_color(stylePoi.getLabelNormalFontOutlineColor());
			normalLabel.setShadow_offset(stylePoi.getLabelNormalFontShadowOffset());
			normalLabel.setShadow_ColorAndOpacity(stylePoi.getLabelNormalFontShadowColorandopacity());
			normalLabel.setOffset(stylePoi.getLabelNormalOffset());
			normalLabel.setPadding(stylePoi.getLabelNormalPadding());
			normalLabel.setBg_color(stylePoi.getLabelNormalBgColor());
			
			/**
			 * POI点Label activate 样式组装
			 */
			LabelForUEItem activateLabel=new LabelForUEItem();
			activateLabel.setText(poi.getCnText());
//			activateLabel.setShow_label(stylePoi.getLabelActivateShowLabel());
			normalLabel.setShow_label(true);
			activateLabel.setFont_size(stylePoi.getLabelActivateFontSize());
			activateLabel.setFont_style(stylePoi.getLabelActivateFontStyle());
			activateLabel.setFont_family(stylePoi.getLabelActivateFontFamily());
			activateLabel.setColor(stylePoi.getLabelActivateFontColor());
			activateLabel.setOutline_size(stylePoi.getLabelActivateFontOutlineSize());
			activateLabel.setOutline_color(stylePoi.getLabelActivateFontOutlineColor());
			activateLabel.setShadow_offset(stylePoi.getLabelActivateFontShadowOffset());
			activateLabel.setShadow_ColorAndOpacity(stylePoi.getLabelActivateFontShadowColorandopacity());
			activateLabel.setOffset(stylePoi.getLabelActivateOffset());
			activateLabel.setPadding(stylePoi.getLabelActivatePadding());
			activateLabel.setBg_color(stylePoi.getLabelActivateBgColor());
			
			labelForUE.setNormal(normalLabel);
			labelForUE.setActivate(activateLabel);
			
			MarkerForUE markerForUE=new MarkerForUE();
			/**
			 * POI点Marker normal 样式组装
			 */
			MarkerForUEItem normalMarker=new MarkerForUEItem();
			normalMarker.setUrl(stylePoi.getMarkerNormalUrl());
			normalMarker.setSize(stylePoi.getMarkerNormalSize());
			
			/**
			 * POI点Marker activate 样式组装
			 */
			MarkerForUEItem activateMarker=new MarkerForUEItem();
			activateMarker.setUrl(stylePoi.getMarkerActivateUrl());
			activateMarker.setSize(stylePoi.getMarkerActivateUrl());
			
			markerForUE.setNormal(normalMarker);
			markerForUE.setActivate(activateMarker);
			
			poiForUE.setLabel(labelForUE);
			poiForUE.setMarker(markerForUE);
			res.add(poiForUE);
		}
		return R.ok(res);
	}

	@Override
	public R<Object> findList(JSONObject param) {
		
		String identify=param.getString("identify");
		
		List<SubPoi> poiList=SubPoi.dao.find("select * from poi where id in ( select e.element_id FROM layer_element e ,layer l WHERE e.layer_id=l.id and l.identify=?)",identify);
		SubLayerStylePoi stylePoi=SubLayerStylePoi.dao.findFirst("select * from layer_style_poi  s, layer l   where  s.id=l.id and l.identify=? ",identify);
		if(stylePoi==null) {
			return R.failed();
		}
		
		List<POIForUE> res = new LinkedList<POIForUE>();
		for(SubPoi poi:poiList) {

			POIForUE poiForUE=new POIForUE();
			poiForUE.setId(poi.getId());
			poiForUE.setCoord_type(poi.getCoordType());
			poiForUE.setCoord(poi.getCoord());
			poiForUE.setSpace(stylePoi.getSpace());
//			poiForUE.setShow_icon(stylePoi.getShowIcon());
			poiForUE.setShow_icon(true);
			poiForUE.setShow_range(stylePoi.getShowRange());
			
			LabelForUE labelForUE=new LabelForUE();
			
			/**
			 * POI点Label normal 样式组装
			 */
			LabelForUEItem normalLabel=new LabelForUEItem();
			normalLabel.setText(poi.getCnText());
//			normalLabel.setShow_label(stylePoi.getLabelNormalShowLabel());
			normalLabel.setShow_label(true);
			normalLabel.setFont_size(stylePoi.getLabelNormalFontSize());
			normalLabel.setFont_style(stylePoi.getLabelNormalFontStyle());
			normalLabel.setFont_family(stylePoi.getLabelNormalFontFamily());
			normalLabel.setColor(stylePoi.getLabelNormalFontColor());
			normalLabel.setOutline_size(stylePoi.getLabelNormalFontOutlineSize());
			normalLabel.setOutline_color(stylePoi.getLabelNormalFontOutlineColor());
			normalLabel.setShadow_offset(stylePoi.getLabelNormalFontShadowOffset());
			normalLabel.setShadow_ColorAndOpacity(stylePoi.getLabelNormalFontShadowColorandopacity());
			normalLabel.setOffset(stylePoi.getLabelNormalOffset());
			normalLabel.setPadding(stylePoi.getLabelNormalPadding());
			normalLabel.setBg_color(stylePoi.getLabelNormalBgColor());
			
			/**
			 * POI点Label activate 样式组装
			 */
			LabelForUEItem activateLabel=new LabelForUEItem();
			activateLabel.setText(poi.getCnText());
//			activateLabel.setShow_label(stylePoi.getLabelActivateShowLabel());
			normalLabel.setShow_label(true);
			activateLabel.setFont_size(stylePoi.getLabelActivateFontSize());
			activateLabel.setFont_style(stylePoi.getLabelActivateFontStyle());
			activateLabel.setFont_family(stylePoi.getLabelActivateFontFamily());
			activateLabel.setColor(stylePoi.getLabelActivateFontColor());
			activateLabel.setOutline_size(stylePoi.getLabelActivateFontOutlineSize());
			activateLabel.setOutline_color(stylePoi.getLabelActivateFontOutlineColor());
			activateLabel.setShadow_offset(stylePoi.getLabelActivateFontShadowOffset());
			activateLabel.setShadow_ColorAndOpacity(stylePoi.getLabelActivateFontShadowColorandopacity());
			activateLabel.setOffset(stylePoi.getLabelActivateOffset());
			activateLabel.setPadding(stylePoi.getLabelActivatePadding());
			activateLabel.setBg_color(stylePoi.getLabelActivateBgColor());
			
			labelForUE.setNormal(normalLabel);
			labelForUE.setActivate(activateLabel);
			
			MarkerForUE markerForUE=new MarkerForUE();
			/**
			 * POI点Marker normal 样式组装
			 */
			MarkerForUEItem normalMarker=new MarkerForUEItem();
			normalMarker.setUrl(stylePoi.getMarkerNormalUrl());
			normalMarker.setSize(stylePoi.getMarkerNormalSize());
			
			/**
			 * POI点Marker activate 样式组装
			 */
			MarkerForUEItem activateMarker=new MarkerForUEItem();
			activateMarker.setUrl(stylePoi.getMarkerActivateUrl());
			activateMarker.setSize(stylePoi.getMarkerActivateUrl());
			
			markerForUE.setNormal(normalMarker);
			markerForUE.setActivate(activateMarker);
			
			poiForUE.setLabel(labelForUE);
			poiForUE.setMarker(markerForUE);
			res.add(poiForUE);
		}
		return R.ok(res);
	}

}
